package com.quanshu.exchange.ui.gui.profile;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.entity.TcDataBean;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.ui.base.BaseDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.subjects.BehaviorSubject;

public class Dialog_details extends BaseDialog {

    @BindView(R.id.status_one)
    TextView statusOne;
    @BindView(R.id.status_two)
    TextView statusTwo;
    @BindView(R.id.status_three)
    TextView statusThree;
    @BindView(R.id.status_four)
    TextView statusFour;
    @BindView(R.id.back)
    RelativeLayout back;
    @BindView(R.id.enter_harvest)
    TextView enterHarvest;

    private TcDataBean dataBean;

    public Dialog_details(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_details);
        ButterKnife.bind(this);
        initView();
        initListener();
    }

    private BehaviorSubject behaviorSubject = BehaviorSubject.create();

    public BehaviorSubject getBehaviorSubject() {
        return behaviorSubject;
    }

    private void initListener() {
        RxViewHelper.getInstance().clicks(back, aVoid -> {
            dismiss();
        });

        RxViewHelper.getInstance().clicks(enterHarvest, o -> {
            behaviorSubject.onNext(o);
        });
    }

    private void initView() {

        if (dataBean.getStatusname().equals("待发货")) {
            statusOne.setVisibility(View.VISIBLE);
            statusTwo.setVisibility(View.VISIBLE);
            statusThree.setVisibility(View.GONE);
            statusFour.setVisibility(View.GONE);
            enterHarvest.setVisibility(View.GONE);

            statusOne.setText("套餐类型：" + dataBean.getPackage_name());
            statusTwo.setText("发货状态：" + dataBean.getStatusname());


        } else if (dataBean.getStatusname().equals("已发货")) {
            statusOne.setVisibility(View.VISIBLE);
            statusTwo.setVisibility(View.VISIBLE);
            statusThree.setVisibility(View.VISIBLE);
            statusFour.setVisibility(View.VISIBLE);
            enterHarvest.setVisibility(View.VISIBLE);

            statusOne.setText("套餐类型：" + dataBean.getPackage_name());
            statusTwo.setText("发货状态：" + dataBean.getStatusname());
            statusThree.setText("发货时间：" + dataBean.getDistribution_time());
            statusFour.setText("派件人手机号：" + dataBean.getMobile());


        } else if (dataBean.getStatusname().equals("已收货")) {

            statusOne.setVisibility(View.VISIBLE);
            statusTwo.setVisibility(View.VISIBLE);
            statusThree.setVisibility(View.VISIBLE);
            statusFour.setVisibility(View.VISIBLE);
            enterHarvest.setVisibility(View.GONE);

            statusOne.setText("套餐类型：" + dataBean.getPackage_name());
            statusTwo.setText("发货状态：" + dataBean.getStatusname());
            statusThree.setText("发货时间：" + dataBean.getDistribution_time());
            statusFour.setText("收货时间：" + dataBean.getEnd_time());


        } else if (dataBean.getStatusname().equals("已自提")) {

            statusOne.setVisibility(View.VISIBLE);
            statusTwo.setVisibility(View.VISIBLE);
            statusThree.setVisibility(View.VISIBLE);
            statusFour.setVisibility(View.GONE);
            enterHarvest.setVisibility(View.GONE);

            statusOne.setText("套餐类型：" + dataBean.getPackage_name());
            statusTwo.setText("发货状态：" + dataBean.getStatusname());
            statusThree.setText("自提时间：" + dataBean.getDistribution_time());
        }
    }

    @Override
    public void init(@NonNull Context context) {
        Window window = getWindow();
        window.setWindowAnimations(R.style.BottomAnim);
        window.setGravity(Gravity.CENTER);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度,由dialog的布局自己来决定实际显示宽度
        window.getDecorView().setPadding(60, 0, 60, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    public void setData(TcDataBean tcDataBean) {
        dataBean = tcDataBean;
    }


    @Override
    public boolean isCancelAble() {
        return true;
    }
}
